package com.example.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/login")
public class LoginController extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        // 简单的登录验证逻辑
        if ("xiaoming".equals(username) && "123456".equals(password)) {
            // 登录成功，设置用户信息到session
            request.getSession().setAttribute("username", username);
            request.getSession().setAttribute("major", "计算机科学");
            request.getSession().setAttribute("grade", "2020");
            request.getSession().setAttribute("class", "1");
            request.getSession().setAttribute("contact", "1234567890");
            response.sendRedirect("info.jsp");
        } else {
            // 登录失败，重定向到错误页面
            response.sendRedirect("error.jsp");
        }
    }
}